/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pbs.util;

import java.util.Map;
import java.util.ResourceBundle;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;

/**
 * Hibernate Utility class with a convenient method to get Session Factory object.
 *
 * @author Luiz Segundo
 */
public class HibernateUtil {

        private static final String FILE_BASE = "project";
        private static final String USED_PU = "conf";
        private static final SessionFactory sessionFactory;
        private static final ResourceBundle resource;
        private static final String persistence;

        private HibernateUtil(){
                
        }

        static {
                try {
                        resource = ResourceBundle.getBundle(FILE_BASE);
                        persistence = resource.getString(USED_PU);
                        // Create the SessionFactory from standard (hibernate.cfg.xml)
                        // config file.
                        sessionFactory = new AnnotationConfiguration().configure(persistence).buildSessionFactory();
                } catch (Throwable ex) {
                        // Log the exception.
                        System.err.println("Initial SessionFactory creation failed." + ex);
                        throw new ExceptionInInitializerError(ex);
                }
        }

        public static SessionFactory getSessionFactory() {
                return sessionFactory;
        }
}
